<?php
/**
 * Created by PhpStorm.
 * User: 公用服务类
 * Date: 2017/6/23
 * Time: 11:48
 */

namespace WMApi\Service;


class PublicServer {

    /**
     * 获取订单支付类型
     * 
     * @param int $pay_id 支付方式 （1-微信支付 2-支付宝 3-余额支付 7-京东支付）;
     * 
     * @author ^2_3^
     */
    public function get_pay_type( $pay_id=0 ){
        $pay_type = '';
        
        switch ( $pay_id ){
            case 0:
                $pay_type = '未选择';
                break;
            case 1:
                $pay_type = '微信支付';
                break;
            case 2:
                $pay_type = '支付宝';
                break;
            case 3:
                $pay_type = '余额支付';
                break;
            case 7:
                $pay_type = '京东支付';
                break;
            default:
                $pay_type = '其他支付';
        }
        
        return $pay_type;
    }
    
    /**
     * 获取订单状态文本
     * 
     * @param int $order_status 订单状态 （0-未付款 1-已付款 2-已取消  3-已退款）;
     * @param int $seller_status 商家状态 （0-未接单 1-已接单 2-拒接单 3-取消订单 ）;
     * @param int $tail_end_status 配送状态(末端状态) （1-未接单，2-已接单，3-配送中，4已送达）;
     * 
     * @author ^2_3^
     */
    public function get_order_status_text($order_status=0, $seller_status=0, $tail_end_status=0) {
        $text = '';
        
        if( $order_status == 0 ) {
            $text = '未付款';
            
        }else if( $order_status == 2 ) {
            $text = '已取消';
                
        }else if( $order_status == 3 ) {
            $text = '已退款';
            
        }else if( $seller_status == 0 ) {
            $text = "等待商家接单";
            
        }else if( $seller_status == 2 ) {
            $text = "商家拒绝接单";
            
        }else if( $seller_status == 3 ) {
            $text = "商家取消订单";
            
        }else if( $tail_end_status == 1) {
            $text = "等待骑手接单";
            
        }else if( $tail_end_status == 2 ) {
            $text = "骑手正在赶往商家取货";
            
        }else if( $tail_end_status == 3 ) {
            $text = "骑手配送中";
            
        }else if( $tail_end_status == 4 ) {
            $text = "骑手已送达";
        }
        
        return  $text;
    }
    
    /**
     * 处理期望配送时间
     * Created By caicm
     * @param string $expect_time 期望配送时间段 (22:00-23:00)
     * @return mixed
     */
    public function get_expect_time($expect_time=''){

        $expect_time = explode('-', $expect_time);
        if(count($expect_time) != 2){
            returnApiError('期望配送时间参数有误');
        }


        return array(
            //配送期望时间-开始
            'shipping_expect_time_start' => timetogmtime($expect_time[0]),
            //配送期望时间-结束
            'shipping_expect_time_end' => timetogmtime($expect_time[1]),
        );

    }
}